package it.tukano.log;

import java.util.concurrent.atomic.AtomicInteger;

public class Log {
    
    public static final AtomicInteger STACK_DEEPNESS = new AtomicInteger(5);

    /**
     * Instance initializer
     */
    public Log() {
    }
    
    public static void implementThis() {
        doMessage(3, "Implement This");
    }
    
    public static void message(Object... tokens) {
        doMessage(3, "Log.Message", tokens);
    }
    
    static void doMessage(int stackIndex, String header, Object... tokens) {
        Thread currentThread = Thread.currentThread();
        StackTraceElement[] stackTrace = currentThread.getStackTrace();
        StringBuilder buffer = new StringBuilder();
        buffer.append(header).append("\n");
        int max = STACK_DEEPNESS.get();
        for(int i = 0; i < max; i++) {
            int index = stackIndex + i;
            if(index >= stackTrace.length) break;
            buffer.append(stackTrace[index]).append("\n");
        }
        buffer.append("\n");
        if(tokens != null) for (int i = 0; i < tokens.length; i++) {
            Object object = tokens[i];
            buffer.append(object);
        }
        System.out.println(buffer);
    }
}
